package com.kedacom.demo.rabbitmq_java_client.ch1.helloworld;

import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Sender {

	public static void main(String[] args) throws java.io.IOException, TimeoutException {
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost(Constants.RABBITMQ_HOST);
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();

		channel.queueDeclare(Constants.QUEUE_NAME, false, false, false, null);
		String message = "Hello World!";
		channel.basicPublish("", Constants.QUEUE_NAME, null, message.getBytes());
		System.out.println(" [x] Sent '" + message + "'");

		// =INFO REPORT==== 21-Dec-2012::10:51:23 ===
		// accepting AMQP connection <0.213.0> (172.16.48.14:53158 ->
		// 172.16.217.182:5672)
		// =INFO REPORT==== 21-Dec-2012::10:51:23 ===
		// closing AMQP connection <0.213.0> (172.16.48.14:53158 ->
		// 172.16.217.182:5672)

		channel.close();
		connection.close();
	}

}
